package com.rxjava;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by kkmike999 on 16/3/21.
 */
public class rxTest {
    public static void main(String[] args) {
        // 发送事件A B C,并显示
        Observable.just("A");

        Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                try {
                    subscriber.onNext(1 / 0 + "");
                    subscriber.onNext("A");
                    subscriber.onCompleted();
                } catch (Exception e) {
                    subscriber.onError(new Throwable("陶伟基是傻逼"));
                }
            }
        })
                .subscribe(new Subscriber<String>() {
                    @Override
                    public void onCompleted() {
                        System.out.println("onCompleted");
                    }

                    @Override
                    public void onError(Throwable throwable) {
//                        System.out.println(throwable.getMessage());
                        throwable.printStackTrace();
                    }

                    @Override
                    public void onNext(String s) {
                        System.out.println(s);
                    }
                });
    }
}
